home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12633 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: solon.com!not-for-mail
  2. From: seebs@solutions.solon.com (Peter Seebach)
  3. Newsgroups: comp.lang.c,comp.os.ms-windows.programmer.win32
  4. Subject: Re: How can I check whether I file exists in a multi-user environment?
  5. Date: 1 Apr 1996 19:37:39 -0600
  6. Organization: Usenet Fact Police (Undercover)
  7. Message-ID: <4jq0d3$9pd@solutions.solon.com>
  8. References: <4jh4tl$t4c_002@chem.uva.nl> <Dp1oM8.Cns@iquest.net> <4jjn1d$clu@solutions.solon.com> <Dp6sqL.Buz@iquest.net>
  9. NNTP-Posting-Host: solutions.solon.com
  10.  
  11. In article <Dp6sqL.Buz@iquest.net>, Doug Miller <dlmiller@iquest.net> wrote:
  12. >seebs@solutions.solon.com (Peter Seebach) wrote:
  13. >>The reason this is a poor solution is that it doesn't test for existance,
  14. >>it tests for accessibility.
  15.  
  16. >You should check your facts more carefully.  You evidently are unfamiliar
  17. >with the behavior of access( ).  It is defined thusly:
  18.  
  19. It isn't defined at all, except by various external standards.
  20.  
  21. POSIX defines it one way.
  22.  
  23. >#include <io.h>
  24.  
  25. As noted, this is incorrect for the only actual *standard* that specifies
  26. access.  It's <unistd.h>
  27.  
  28. >permissible values for amode are:
  29. >    06    check for read and write permission
  30. >    04    check for read permission
  31. >    02    check for write permission
  32. >    01    execute
  33. >>>>>    00    check for existence of file    <<<<<
  34.  
  35. This is all incorrect.  The modes are R_OK, X_OK, W_OK, and F_OK, and may
  36. be ored.  Quoting specific numbers from a specific implementation is
  37. unuseful.
  38.  
  39. >Return value: If the requested access is allowed, access() returns 0;
  40. >otherwise it returns a value
  41. >of -1, and the global variable errno is set to one of the following:
  42. >    ENOENT        Path or file name not found
  43. >    EACCES        Permission denied
  44.  
  45. >As I coded it, this is a test for the existence of the file, not its
  46. >accessibility.
  47.  
  48. You missed the point completely, dimwit.  Create a file.  Now mark the
  49. directory it's in unreadable, unwriteable, unexecutable, etc etc.
  50.  
  51. Now try your test.  And gee, you'll get EACCES, most likely.  Because,
  52. if you don't have the permissions needed to look in the directory,
  53. it's *IMPOSSIBLE* to test for existance.
  54.  
  55. As I said, this tests for accessability.
  56.  
  57. Feel free to email me a sample program, using POSIX standard code, and I'll
  58. gladly test it.  :)
  59.  
  60. (But this really should leave the newsgroup now.)
  61.  
  62. -s
  63. -- 
  64. Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
  65. C/Unix wizard -- C/Unix questions? Send mail for help.  No, really!
  66. FUCK the communications decency act.  Goddamned government.  [literally.]
  67. The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
  68.